VERSION 5.00
Begin VB.Form frmMain 
   Caption         =   "*"
   ClientHeight    =   7200
   ClientLeft      =   60
   ClientTop       =   750
   ClientWidth     =   9600
   Icon            =   "frmMain.frx":0000
   LockControls    =   -1  'True
   ScaleHeight     =   7200
   ScaleWidth      =   9600
   Begin VB.TextBox txtBoard 
      BorderStyle     =   0  'None
      BeginProperty Font 
         Name            =   "Fixedsys"
         Size            =   9
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   7215
      Left            =   0
      MultiLine       =   -1  'True
      ScrollBars      =   3  'Both
      TabIndex        =   0
      Top             =   0
      Width           =   9615
   End
   Begin VB.Menu mnuPrograms 
      Caption         =   "*"
      Begin VB.Menu mnuClear 
         Caption         =   "*"
         Shortcut        =   {F5}
      End
      Begin VB.Menu mnuSkip0 
         Caption         =   "-"
      End
      Begin VB.Menu mnuReadCLP 
         Caption         =   "*"
         Shortcut        =   ^R
      End
      Begin VB.Menu mnuCopyCLP 
         Caption         =   "*"
         Shortcut        =   ^W
      End
      Begin VB.Menu mnuSkip1 
         Caption         =   "-"
      End
      Begin VB.Menu mnuQuadratic 
         Caption         =   "*"
      End
      Begin VB.Menu mnuConversion 
         Caption         =   "*"
      End
      Begin VB.Menu mnuGraph 
         Caption         =   "*"
      End
      Begin VB.Menu mnuSkip2 
         Caption         =   "-"
      End
      Begin VB.Menu mnuExit 
         Caption         =   "*"
         Shortcut        =   ^{F4}
      End
   End
   Begin VB.Menu mnuSettings 
      Caption         =   "*"
      Begin VB.Menu mnuTrigonometrics 
         Caption         =   "*"
         Begin VB.Menu mnuTrigonometricsID 
            Caption         =   "*"
            Index           =   0
            Shortcut        =   +^{F1}
         End
         Begin VB.Menu mnuTrigonometricsID 
            Caption         =   "*"
            Index           =   1
            Shortcut        =   +^{F2}
         End
      End
      Begin VB.Menu mnuDecimalPrecision 
         Caption         =   "*"
         Begin VB.Menu mnuDP 
            Caption         =   "0"
            Index           =   0
         End
         Begin VB.Menu mnuSkip3 
            Caption         =   "-"
         End
         Begin VB.Menu mnuNoneDP 
            Caption         =   "*"
            Shortcut        =   +^{F12}
         End
      End
      Begin VB.Menu mnuSpecial 
         Caption         =   "*"
         Begin VB.Menu mnuIsMeanXOR 
            Caption         =   "*"
         End
      End
      Begin VB.Menu mnuLog 
         Caption         =   "*"
      End
      Begin VB.Menu mnuConstants 
         Caption         =   "*"
         Visible         =   0   'False
      End
      Begin VB.Menu mnuFonts 
         Caption         =   "*"
      End
      Begin VB.Menu mnuTop 
         Caption         =   "*"
      End
   End
   Begin VB.Menu mnuPluginMenu 
      Caption         =   "*"
      Begin VB.Menu mnuPlugins 
         Caption         =   "*"
         Index           =   0
      End
   End
   Begin VB.Menu mnuHelp 
      Caption         =   "*"
      Begin VB.Menu mnuAbout 
         Caption         =   "*"
         Shortcut        =   {F1}
      End
   End
End
Attribute VB_Name = "frmMain"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit

Dim lpDP As Long

Private Sub Form_Load()
    On Error Resume Next
    Dim strPCount As String
    Dim lpCurrent As Long
    Dim strInputRG As String
    frmMain.Caption = LoadGlobalLanguage(101)
    mnuPrograms.Caption = LoadGlobalLanguage(102)
    mnuClear.Caption = LoadGlobalLanguage(103)
    mnuExit.Caption = LoadGlobalLanguage(104)
    mnuSettings.Caption = LoadGlobalLanguage(105)
    mnuTrigonometrics.Caption = LoadGlobalLanguage(106)
    mnuTrigonometricsID(0).Caption = LoadGlobalLanguage(107)
    mnuTrigonometricsID(1).Caption = LoadGlobalLanguage(108)
    mnuDecimalPrecision.Caption = LoadGlobalLanguage(109)
    mnuNoneDP.Caption = LoadGlobalLanguage(110)
    mnuFonts.Caption = LoadGlobalLanguage(111)
    mnuTop.Caption = LoadGlobalLanguage(112)
    mnuHelp.Caption = LoadGlobalLanguage(113)
    mnuAbout.Caption = LoadGlobalLanguage(114)
    mnuConstants.Caption = LoadGlobalLanguage(115)
    mnuGraph.Caption = LoadGlobalLanguage(116)
    mnuLog.Caption = LoadGlobalLanguage(117)
    mnuReadCLP.Caption = LoadGlobalLanguage(118)
    mnuCopyCLP.Caption = LoadGlobalLanguage(119)
    mnuQuadratic.Caption = LoadGlobalLanguage(120)
    mnuConversion.Caption = LoadGlobalLanguage(121)
    mnuPluginMenu.Caption = LoadGlobalLanguage(122)
    mnuIsMeanXOR.Caption = LoadGlobalLanguage(126)
    mnuSpecial.Caption = LoadGlobalLanguage(127)
    For lpCurrent = 0 To 9
        If lpCurrent <> 0 Then
            Load mnuDP(lpCurrent)
            mnuDP(lpCurrent).Caption = Trim(Str(lpCurrent))
            mnuDP(lpCurrent).Visible = True
        Else
            mnuDP(lpCurrent).Caption = Trim(Str(lpCurrent))
            mnuDP(lpCurrent).Visible = True
        End If
        DoEvents
    Next lpCurrent
    strInputRG = GetSetting(App.EXEName, "Settings", "DecimalPrecision", "-1")
    If IsNumeric(strInputRG) = False Then
        strInputRG = "-1"
    End If
    If Val(strInputRG) < -1 Or Val(strInputRG) > 9 Then
        strInputRG = "-1"
    End If
    If strInputRG >= 0 Then
        Call mnuDP_Click(Val(strInputRG))
    Else
        Call mnuNoneDP_Click
    End If
    strInputRG = GetSetting(App.EXEName, "Settings", "RadianWay", "0")
    If Trim(Str(strInputRG)) = "1" Then
        Call mnuTrigonometricsID_Click(1)
    Else
        Call mnuTrigonometricsID_Click(0)
    End If
    strInputRG = GetSetting(App.EXEName, "Fonts", "Name", txtBoard.FontName)
    txtBoard.FontName = strInputRG
    strInputRG = GetSetting(App.EXEName, "Fonts", "Italic", "0")
    txtBoard.FontItalic = IIf(Trim(strInputRG) = "1", True, False)
    strInputRG = GetSetting(App.EXEName, "Fonts", "Strikethru", "0")
    txtBoard.FontStrikethru = IIf(Trim(strInputRG) = "1", True, False)
    strInputRG = GetSetting(App.EXEName, "Fonts", "Underline", "0")
    txtBoard.FontUnderline = IIf(Trim(strInputRG) = "1", True, False)
    strInputRG = GetSetting(App.EXEName, "Fonts", "Weight", Trim(Str(txtBoard.Font.Weight)))
    If IsNumeric(strInputRG) = True Then
        txtBoard.Font.Weight = Val(strInputRG)
    End If
    strInputRG = GetSetting(App.EXEName, "Fonts", "Charset", Trim(Str(txtBoard.Font.Charset)))
    If IsNumeric(strInputRG) = True Then
        txtBoard.Font.Charset = Val(strInputRG)
    End If
    strInputRG = GetSetting(App.EXEName, "Fonts", "Size", Trim(Str(txtBoard.FontSize)))
    If IsNumeric(strInputRG) = True Then
        txtBoard.FontSize = Val(strInputRG)
    End If
    strInputRG = GetSetting(App.EXEName, "Fonts", "Color", "0")
    If IsNumeric(strInputRG) = True Then
        txtBoard.ForeColor = Val(strInputRG)
    End If
    strInputRG = GetSetting(App.EXEName, "Windows", "Width", Trim(Str(frmMain.ScaleWidth)))
    If IsNumeric(strInputRG) = True Then
        frmMain.Width = Val(strInputRG)
    End If
    strInputRG = GetSetting(App.EXEName, "Windows", "Height", Trim(Str(frmMain.ScaleHeight)))
    If IsNumeric(strInputRG) = True Then
        frmMain.Height = Val(strInputRG)
    End If
    strInputRG = GetSetting(App.EXEName, "Windows", "Top", Trim(Str(Screen.Height / 2 - frmMain.ScaleHeight / 2)))
    If IsNumeric(strInputRG) = True Then
        frmMain.Top = Val(strInputRG)
    End If
    strInputRG = GetSetting(App.EXEName, "Windows", "Left", Trim(Str(Screen.Width / 2 - frmMain.ScaleWidth / 2)))
    If IsNumeric(strInputRG) = True Then
        frmMain.Left = Val(strInputRG)
    End If
    strInputRG = GetSetting(App.EXEName, "Windows", "TopMost", "0")
    If Trim(strInputRG) = "1" Then
        Call mnuTop_Click
    End If
    lpLogBase = LoadNumberSetup(App.EXEName, "Settings\Log", "Base", 10)
    If lpLogBase <= 0 Then
        lpLogBase = 10
    End If
    txtBoard.Text = vbNullString
    strInputRG = GetSetting(App.EXEName, "XOR", "MeanXOR", "0")
    If Trim(strInputRG) = "1" Then
        Call mnuIsMeanXOR_Click
    End If
    strPCount = GetKeyCodeFromLog("Plugins", "Count", "0", IntoPath(strBase, strPlugins))
    If IsNumeric(strPCount) = False Then
        strPCount = "0"
    End If
    If Val(strPCount) <= 0 Then
        mnuPlugins(0).Caption = LoadGlobalLanguage(123)
        mnuPlugins(0).Enabled = False
    Else
        For lpCurrent = 1 To Val(strPCount)
            If lpCurrent - 1 <> 0 Then
                Load mnuPlugins(lpCurrent - 1)
            End If
            mnuPlugins(lpCurrent - 1).Visible = True
            mnuPlugins(lpCurrent - 1).Caption = GetKeyCodeFromLog("Plugins", "Name" & Trim(Str(lpCurrent)), "No Name", IntoPath(strBase, strPlugins))
        Next lpCurrent
    End If
    If IsFileOrDirectoryExist(IntoPath(strBase, strConstants)) = True Then
        mnuConstants.Visible = True
    Else
        mnuConstants.Visible = False
    End If
End Sub

Private Sub Form_Resize()
    On Error Resume Next
    With txtBoard
        .Width = frmMain.ScaleWidth
        .Height = frmMain.ScaleHeight
    End With
End Sub

Private Sub Form_Unload(Cancel As Integer)
    On Error Resume Next
    With frmMain
        SaveSetting App.EXEName, "Windows", "Height", Trim(Str(.Height))
        SaveSetting App.EXEName, "Windows", "Width", Trim(Str(.Width))
        SaveSetting App.EXEName, "Windows", "Top", Trim(Str(.Top))
        SaveSetting App.EXEName, "Windows", "Left", Trim(Str(.Left))
    End With
    Cancel = False
    DoEvents
    End
End Sub

Private Sub mnuAbout_Click()
    On Error Resume Next
    Call SetWindowPos(frmMain.hwnd, -2, 0, 0, 0, 0, 3)
    DoEvents
    Load frmAbout
    frmAbout.Show vbModal
    Call SetWindowPos(frmMain.hwnd, IIf(mnuTop.Checked = True, -1, -2), 0, 0, 0, 0, 3)
    DoEvents
End Sub

Private Sub mnuClear_Click()
    On Error Resume Next
    txtBoard.Text = vbNullString
End Sub

Private Sub mnuConstants_Click()
    On Error Resume Next
    If IsFileOrDirectoryExist(IntoPath(strBase, strConstants)) = False Then
        MsgBox LoadGlobalLanguage(203), vbCritical, LoadGlobalLanguage(16)
        Exit Sub
    End If
    ShellExecute frmMain.hwnd, vbNullString, IntoPath(strBase, strConstants), vbNullString, strBase, SW_SHOWNORMAL
End Sub

Private Sub mnuConversion_Click()
    On Error Resume Next
    Call SetWindowPos(frmMain.hwnd, -2, 0, 0, 0, 0, 3)
    DoEvents
    Load frmConversion
    frmConversion.Show vbModal
    Call SetWindowPos(frmMain.hwnd, IIf(mnuTop.Checked = True, -1, -2), 0, 0, 0, 0, 3)
    DoEvents
End Sub

Private Sub mnuCopyCLP_Click()
    On Error Resume Next
    Clipboard.Clear
    Clipboard.SetText txtBoard.Text
End Sub

Private Sub mnuDP_Click(Index As Integer)
    On Error Resume Next
    Dim lpCurrent As Long
    For lpCurrent = 0 To mnuDP.Count - 1
        mnuDP(lpCurrent).Checked = False
        DoEvents
    Next lpCurrent
    mnuNoneDP.Checked = False
    mnuDP(Index).Checked = True
    SaveSetting App.EXEName, "Settings", "DecimalPrecision", Trim(Str(Index))
    lpDP = Index
End Sub

Private Sub mnuExit_Click()
    On Error Resume Next
    Unload frmMain
End Sub

Private Sub mnuFonts_Click()
    On Error Resume Next
    Dim CF As ChooseFont, LF As LOGFONT
    With LF
        .lfFaceName = StrConv(txtBoard.FontName, vbFromUnicode) & vbNullChar
        .lfItalic = txtBoard.FontItalic
        .lfStrikeOut = txtBoard.FontStrikethru
        .lfUnderline = txtBoard.FontUnderline
        .lfWeight = txtBoard.Font.Weight
        .lfCharSet = txtBoard.Font.Charset
        .lfHeight = -MulDiv(txtBoard.FontSize, GetDeviceCaps(hdc, LOGPIXELSY), 72)
    End With
    With CF
        .rgbColors = txtBoard.ForeColor
        .lStructSize = Len(CF)
        .hwndOwner = hwnd
        .hInstance = App.hInstance
        .flags = CF_BOTH Or CF_FORCEFONTEXIST Or CF_INITTOLOGFONTSTRUCT Or CF_EFFECTS Or CF_LIMITSIZE
        .lpLogFont = VarPtr(LF)
        .nSizeMin = 8
        .nSizeMax = 72
    End With
    If ChooseFont(CF) = 0 Then
        Exit Sub
    End If
    With txtBoard
        .FontName = StrConv(LF.lfFaceName, vbUnicode)
        .FontItalic = LF.lfItalic
        .FontStrikethru = LF.lfStrikeOut
        .FontUnderline = LF.lfUnderline
        .Font.Weight = LF.lfWeight
        .Font.Charset = LF.lfCharSet
        .FontSize = -LF.lfHeight - ((-LF.lfHeight) / 4) - IIf(-LF.lfHeight Mod 4 > 1, 1, 0)
        .ForeColor = CF.rgbColors
        SaveSetting App.EXEName, "Fonts", "Name", .FontName
        SaveSetting App.EXEName, "Fonts", "Italic", IIf(.FontItalic = True, "1", "0")
        SaveSetting App.EXEName, "Fonts", "Strikethru", IIf(.FontStrikethru = True, "1", "0")
        SaveSetting App.EXEName, "Fonts", "Underline", IIf(.FontUnderline = True, "1", "0")
        SaveSetting App.EXEName, "Fonts", "Weight", Trim(Str(.Font.Weight))
        SaveSetting App.EXEName, "Fonts", "Charset", Trim(Str(.Font.Charset))
        SaveSetting App.EXEName, "Fonts", "Size", Trim(Str(.FontSize))
        SaveSetting App.EXEName, "Fonts", "Color", Trim(Str(.ForeColor))
    End With
End Sub

Private Sub mnuGraph_Click()
    On Error Resume Next
    Call SetWindowPos(frmMain.hwnd, -2, 0, 0, 0, 0, 3)
    DoEvents
    Load frmGraph
    frmGraph.Show vbModal
    Call SetWindowPos(frmMain.hwnd, IIf(mnuTop.Checked = True, -1, -2), 0, 0, 0, 0, 3)
    DoEvents
End Sub

Private Sub mnuIsMeanXOR_Click()
    On Error Resume Next
    mnuIsMeanXOR.Checked = Not mnuIsMeanXOR.Checked
    bpIsMeanXor = mnuIsMeanXOR.Checked
    SaveSetting App.EXEName, "XOR", "MeanXOR", IIf(mnuIsMeanXOR.Checked = True, "1", "0")
End Sub

Private Sub mnuLog_Click()
    On Error Resume Next
    Dim strInput As String
    strInput = InputBox(LoadGlobalLanguage(204), LoadGlobalLanguage(205), Trim(Str(lpLogBase)))
    If IsNumeric(strInput) = True Then
        If Val(strInput) > 0 Then
            lpLogBase = Val(strInput)
            SaveSetting App.EXEName, "Settings\Log", "Base", Trim(Str(lpLogBase))
        Else
            MsgBox LoadGlobalLanguage(206), vbCritical, LoadGlobalLanguage(16)
        End If
    Else
        If Trim(strInput) <> vbNullString Then
            MsgBox LoadGlobalLanguage(207), vbCritical, LoadGlobalLanguage(16)
        End If
    End If
End Sub

Private Sub mnuNoneDP_Click()
    On Error Resume Next
    Dim lpCurrent As Long
    For lpCurrent = 0 To mnuDP.Count - 1
        mnuDP(lpCurrent).Checked = False
        DoEvents
    Next lpCurrent
    mnuNoneDP.Checked = True
    SaveSetting App.EXEName, "Settings", "DecimalPrecision", "-1"
    lpDP = -1
End Sub

Private Sub mnuPlugins_Click(Index As Integer)
    Dim strPath As String
    strPath = GetKeyCodeFromLog("Plugins", "Path" & Trim(Str(Index + 1)), vbNullString, IntoPath(strBase, strPlugins))
    If Trim(strPath) <> vbNullString Then
        If IsFileOrDirectoryExist(IntoPath(strBase, strPath)) = True Then
            ShellExecute frmMain.hwnd, vbNullString, IntoPath(strBase, strPath), vbNullString, strBase, SW_SHOWNORMAL
        Else
            MsgBox LoadGlobalLanguage(124), vbCritical, LoadGlobalLanguage(16)
        End If
    Else
        MsgBox LoadGlobalLanguage(125), vbCritical, LoadGlobalLanguage(16)
    End If
End Sub

Private Sub mnuQuadratic_Click()
    On Error Resume Next
    Call SetWindowPos(frmMain.hwnd, -2, 0, 0, 0, 0, 3)
    DoEvents
    Load frmQuadratic
    frmQuadratic.Show vbModal
    Call SetWindowPos(frmMain.hwnd, IIf(mnuTop.Checked = True, -1, -2), 0, 0, 0, 0, 3)
    DoEvents
End Sub

Private Sub mnuReadCLP_Click()
    On Error Resume Next
    txtBoard.Text = txtBoard.Text & IIf(Trim(Clipboard.GetText()) = vbNullString, vbNullString, vbCrLf) & Clipboard.GetText() & IIf(Trim(Clipboard.GetText()) = vbNullString, vbNullString, vbCrLf)
End Sub

Private Sub mnuTop_Click()
    On Error Resume Next
    mnuTop.Checked = Not mnuTop.Checked
    Call SetWindowPos(frmMain.hwnd, IIf(mnuTop.Checked = True, -1, -2), 0, 0, 0, 0, 3)
    SaveSetting App.EXEName, "Windows", "TopMost", IIf(mnuTop.Checked = True, "1", "0")
End Sub

Private Sub mnuTrigonometricsID_Click(Index As Integer)
    On Error Resume Next
    Dim lpCurrent As Long
    For lpCurrent = 0 To mnuTrigonometricsID.Count - 1
        mnuTrigonometricsID(lpCurrent).Checked = False
        DoEvents
    Next lpCurrent
    mnuTrigonometricsID(Index).Checked = True
    bpRadianWay = IIf(mnuTrigonometricsID(1).Checked = True, True, False)
    SaveSetting App.EXEName, "Settings", "RadianWay", IIf(mnuTrigonometricsID(1).Checked = True, "1", "0")
End Sub

Private Sub txtBoard_KeyPress(KeyAscii As Integer)
    On Error Resume Next
    Dim lP As Long, lcP As Long
    Dim strSelected As String
    Dim lpReturn As Long
    Dim enuSubReturn As enuReturns
    Dim strPrint As String
    Dim strOut As String
    lcP = txtBoard.SelStart + 1
    If KeyAscii = 13 Then
        Do While lcP < Len(txtBoard.Text)
            If Asc(Mid(txtBoard.Text, lcP, 1)) = 13 Then
                Exit Do
            End If
            lcP = lcP + 1
        Loop
        lP = lcP - 1
        Do While lP > 0
            If Asc(Mid(txtBoard.Text, lP, 1)) = 10 Then
                Exit Do
            End If
            lP = lP - 1
        Loop
        strSelected = Mid(txtBoard.Text, lP + 1, lcP - lP)
        strSelected = ResolveString(strSelected, Chr(13), vbNullString)
        strSelected = ResolveString(strSelected, Chr(10), vbNullString)
        strSelected = ResolveString(strSelected, "[", "(", "{", "(", "]", ")", "}", ")")
        If Left(Trim(strSelected), 1) = "'" Or Left(Trim(strSelected), 1) = ";" Then
            GoTo NullInput
        End If
        strOut = CalculateString(strSelected, enuSubReturn)
        If enuSubReturn = lpSucceed Then
            If lpDP >= 0 Then
                strOut = Trim(Str(Round(Val(strOut), lpDP)))
            End If
            If Left(Trim(strOut), 1) = "." Then
                strOut = "0" & strOut
            End If
            strPrint = "=" & strOut
        ElseIf enuSubReturn = lpRunError Then
            strPrint = LoadGlobalLanguage(202)
        ElseIf enuSubReturn = lpSyntaxError Then
            strPrint = LoadGlobalLanguage(201)
        End If
        If Trim(strSelected) <> vbNullString Then
            txtBoard.Text = txtBoard.Text & vbCrLf & strPrint & vbCrLf
            txtBoard.SelStart = Len(txtBoard.Text)
        Else
            KeyAscii = 0
        End If
    End If
NullInput:
End Sub
